package imageDemo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.image.*;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.geometry.Insets;

// 图片
public class ImageDemo extends Application { 
	private VBox root = new VBox(20);
	private ImageView firstImage;
	private ImageView secondImage;
	
	public static void main(String[] args) {
		Application.launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		root.setPadding(new Insets(20));    // 设置边框宽度
		root.setStyle("-fx-background-color: yellow");
		
		// 加载并显示图片(可加载gif,bmp,jpg,png,jpeg格式)
		firstImage = new ImageView(new Image("image/1.jpg"));
		firstImage.setFitWidth(320);
		firstImage.setPreserveRatio(true);	// 保持原始比例
		
		Rectangle rec = new Rectangle(320, 180);
		rec.setArcWidth(70);
		rec.setArcHeight(70);
		firstImage.setClip(rec);	// 剪辑,以节点和图片重合的部分显示图片(可设置坐标)
		
		secondImage = new ImageView(new Image(
				"http://img.pconline.com.cn/images/upload/upc/tx/wallpaper/1306/28/c0/22682317_1372404233710.jpg"));
		secondImage.setFitWidth(320);
		secondImage.setPreserveRatio(true);
		root.getChildren().addAll(firstImage, secondImage);
		
		Scene scene = new Scene(root);
		stage.setScene(scene);
		stage.show();
	}
}

